#region Copyright (C) 2005-2006 Team MediaPortal

/* 
 *	Copyright (C) 2005-2006 Team MediaPortal
 *	http://www.team-mediaportal.com
 *
 *  This Program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *   
 *  This Program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *   
 *  You should have received a copy of the GNU General Public License
 *  along with GNU Make; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
 *  http://www.gnu.org/copyleft/gpl.html
 *
 */

#endregion

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO.IsolatedStorage;
using System.Windows.Forms;
using MediaPortal.GUI.Library;

namespace DotNetGear.BestRussianTV
{
    public partial class Setup : Form
    {
        public Setup()
        {
            InitializeComponent();
        }

        public static string GetLogin()
        {
            using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings("MyVideoArchiveSetup.xml"))
            {
                return xmlreader.GetValueAsString("Setup", "Login", string.Empty);
            }
        }

        public static string GetPassword()
        {
            using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings("MyVideoArchiveSetup.xml"))
            {
                return xmlreader.GetValueAsString("Setup", "Password", string.Empty);
            }
        }


        public static string GetRecordingPath()
        {
            using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings("MyVideoArchiveSetup.xml"))
            {
                return xmlreader.GetValueAsString("Setup", "RecordingPath", "C:\\Downloads\\VideoArchive\\");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings("MyVideoArchiveSetup.xml"))
                {
                    xmlreader.SetValue("Setup", "Login", textBox1.Text);
                    xmlreader.SetValue("Setup", "Password", textBox2.Text);
                    xmlreader.SetValue("Setup", "RecordingPath", label4.Text);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                MessageBox.Show("Could not save configuration! Probably plugin version does not match running MediaPortal version.");
            }

        }

        private void Setup_Load(object sender, EventArgs e)
        {
            try
            {
                using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings("MyVideoArchiveSetup.xml"))
                {
                    textBox1.Text = GetLogin();
                    textBox2.Text = GetPassword();
                    label4.Text = GetRecordingPath();
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                MessageBox.Show("Could not read configuration. Probably plugin version does not match running MediaPortal version.");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.ShowDialog();
            string p = folderBrowserDialog1.SelectedPath;
            if (p[p.Length - 1] != '\\') p += '\\';
            label4.Text = p;
        }
    }
}